import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
import store, { RootState } from '..';
import { AppDispatch } from '../index';

interface UserState {
  uuid: string;
}

const initialState: UserState = {
  uuid: 'hello-world',
};

export const userSlice = createSlice({
  name: 'user',
  initialState,
  reducers: {
    longer: (state) => {
      state.uuid = state.uuid + '.';
    },
  },
});

export const { longer } = userSlice.actions;

export const selectUuid = (state: RootState) => state.user.uuid;

export default userSlice.reducer;

export function fetchDonkey() {
  return async (dispatch: AppDispatch) => {
    await new Promise((resolve) => setTimeout(resolve, 1000, true));
    dispatch(longer());
  };
}
